import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import MainView from '../views/MainView.vue'
import OtherView from '../views/OtherView.vue'
import OtherOneView from '../views/OtherOneView.vue'
import OtherTwoView from '../views/OtherTwoView.vue'
import UserView from '../views/UserView.vue'
import AppMenuView from '../views/AppMenuView.vue'
import MenuView from '../views/MenuView.vue'
import WebMenuView from '../views/WebMenuView.vue'
import PermissionView from '../views/PermissionView.vue'

import TempView from '../views/TempView.vue'

import UploadView from '@/views/UploadView.vue'

import RoleView from '@/views/RoleView.vue'

import LoginView from '@/views/LoginView.vue'



//备份原型对象已有的push|replace方法
let push = VueRouter.prototype.push;
let replace = VueRouter.prototype.replace;
//重写VueRouter.prototype原型对象的push|replace方法
VueRouter.prototype.push = function (location) {
    //调用push方法且篡改push方法内部this指向->vueRouter类的实例
    push.call(this, location, () => { }, () => { });
}
VueRouter.prototype.replace = function (location) {
    //调用push方法且篡改push方法内部this指向->vueRouter类的实例
    replace.apply(this, [location, () => { }, () => { }]);
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: MainView,
    redirect: '/home',
    children: [
      { path: 'home', component: HomeView },
      { path: 'user', component: UserView },
      { path: 'other', component: OtherView },
      { path: 'other1', component: OtherOneView },
      { path: 'other2', component: OtherTwoView },
      { path: 'menu', component: MenuView },
      { path: 'appmenu', component: AppMenuView },
      { path: 'webmenu', component: WebMenuView },
      { path: 'permission', component: PermissionView },
	  { path: 'temp', component: TempView },
	  { path: 'role', component: RoleView},
	  { path: 'upload', component: UploadView}
    ]
  },{
	  path: '/login',
	  name: 'login',
	  component: LoginView
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router
